#!/usr/bin/env python
# _*_ coding: utf-8 _*_
# @Time    : 2018/5/17 0017 下午 12:01
# @Author  : Jython <ijython@qq.com>
# @File    : mlapi.py

# coding:utf-8
from flask import Flask
import config.config
from util.Grequest import Grequest
from util.Gresponse import Gresponse
from util.Gview import Gview

app = Flask(__name__)

app.config.from_object(config)

@app.before_request
def beforeRequest():
	"""
	前置钩子
	:return:
	"""
	has_auth = Grequest.beforeRequest( )
	if not has_auth:
		return Gview.Vfail("没有权限")

@app.after_request
def afterRequest( response ):
	"""
	后置钩子
	:param f:
	:return:
	"""
	return Grequest.afterRequest(response)

@app.teardown_request
def exceptionRequest( exception ):
	"""
	异常钩子
	:param exception:
	:return:
	"""
	return Gview.Vfail(str(exception), 500)

@app.errorhandler(500)
def exception500( error ):
	"""
	http异常处理钩子
	:param error:
	:return:
	"""
	return Gview.Vfail(str(error), 500)

@app.errorhandler(404)
def exception404( error ):
	"""
	http异常处理钩子
	:param error:
	:return:
	"""
	return Gview.Vfail(str(error), 404)

from trialLesson.controller.successRate import successRate

app.register_blueprint(successRate, url_prefix = '/v1/trialLesson')

app.response_class = Gresponse
if __name__ == '__main__':
	app.run(debug =app.config.get('DEBUG'))
